from itsdangerous import TimedJSONWebSignatureSerializer  as Serializer
from meiduo_mail import settings


def generic_openid(openid):
    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)
    access_token = s.dumps({'openid': openid})
    return access_token.decode()


def check_openid(access_token):
    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)
    try:
        data = s.loads(access_token)
    except Exception as e:
        return None
    else:
        return data.get('openid')
